unit SmtpHelper;

interface
uses
  IdSMTP,IdMessage,DbHelper,uni;
type
  TSmtpHelper=class
  private
    smtp:TIdSMTP;
  public
    constructor Create(zh:string;db:TDbHelper);
    destructor Destroy;
    procedure SendMessage(idmsg:Tidmessage);
  end;

implementation

{ TSmtpHelper }

constructor TSmtpHelper.Create(zh: string; db: TDbHelper);
var
  query:TUniQuery;
begin
  smtp:=TIdSMTP.Create();
  query:=TUniQuery.Create(smtp);
  db.GetSqlStrDataSet(query,'select * from zh_info where email='''+zh+'''',nil);
  if not query.Eof then
  begin
    smtp.Host:=query.FieldByName('smtpserver').AsString;
    smtp.Username:=query.FieldByName('smtpname').AsString;
    smtp.Password:=query.FieldByName('smtppassword').AsString;
    smtp.Port:=query.FieldByName('smtpport').AsInteger;
  end;
  query.Free;
end;

destructor TSmtpHelper.Destroy;
begin
  smtp.Free;
end;

procedure TSmtpHelper.SendMessage(idmsg: Tidmessage);
begin
  //idmsg.From.Name:=;
  smtp.Send(idmsg);
end;

end.
